home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume11 / syslog < prev    next >
Encoding:
Internet Message Format  |  1987-08-27  |  8.0 KB

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v11i022:  Development version of syslog(3), for ATT, too
  5. Message-ID: <1246@uunet.UU.NET>
  6. Date: 28 Aug 87 13:05:20 GMT
  7. Sender: Unknown@uunet.UU.NET
  8. Organization: UUNET Communications Services, Arlington, VA
  9. Lines: 320
  10. Approved: rs@uunet.UU.NET
  11.  
  12. Submitted-by: emory!arnold (Arnold D. Robbins {EUCC})
  13. Posting-number: Volume 11, Issue 22
  14. Archive-name: syslog
  15.  
  16. Here is a version of the BSD syslog(3) routines that write their info
  17. to stderr, instead of to the syslogd daemon. They are useful if you are
  18. developing code that will eventually use the real syslog, but you want
  19. to see the output in the meantime. The file is coded in such a way as
  20. that it may be compiled separately and loaded as a .o file, or it may
  21. be #include'd directly. One possibility is to make it into a library
  22. that could be loaded -lsyslog.
  23.  
  24. There are no comments in the code; see the syslog and printf man pages to
  25. figure out what's going on.
  26.  
  27. There is no makefile since it is just one short piece of source, and no
  28. man page since systems which support syslog (only BSD systems do) already
  29. have man pages that describe the facility.
  30.  
  31. Enjoy,
  32.  
  33. Arnold Robbins
  34.  
  35. [  Actually...  I wrote Makefile, manpage, and header file because I think
  36.    this would be a worthwhile interface for non-BSD Unices to support...
  37.    Sorry Arnold, I got carried away.
  38.    This is also a good example of varargs-coding.  --r$ ]
  39.  
  40. #! /bin/sh
  41. # This is a shell archive.  Remove anything before this line, then unpack
  42. # it by saving it into a file and typing "sh file".  To overwrite existing
  43. # files, type "sh file -c".  You can also feed this as standard input via
  44. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  45. # will see the following message at the end:
  46. #        "End of shell archive."
  47. # Contents:  Makefile syslog.3 syslog.c syslog.h
  48. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  49. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  50.   echo shar: Will not clobber existing file \"'Makefile'\"
  51. else
  52. echo shar: Extracting \"'Makefile'\" \(185 characters\)
  53. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  54. X## syslog routine makefile
  55. XCFLAGS=-O
  56. Xall:    syslog.c
  57. X    $(CC) $(CFLAGS) -c syslog.c
  58. X    ar c libsyslog.a syslog.o
  59. X    @rm -f syslog.o
  60. X
  61. Xinstall:    all
  62. X    @echo install according to local conventions.
  63. END_OF_FILE
  64. if test 185 -ne `wc -c <'Makefile'`; then
  65.     echo shar: \"'Makefile'\" unpacked with wrong size!
  66. fi
  67. # end of 'Makefile'
  68. fi
  69. if test -f 'syslog.3' -a "${1}" != "-c" ; then 
  70.   echo shar: Will not clobber existing file \"'syslog.3'\"
  71. else
  72. echo shar: Extracting \"'syslog.3'\" \(1246 characters\)
  73. sed "s/^X//" >'syslog.3' <<'END_OF_FILE'
  74. X.TH SYSLOG 3 LOCAL
  75. X.SH NAME
  76. Xsyslog, openlog, closelog \- logging routines
  77. X.SH SYNOPSIS
  78. X.nf
  79. X#include <syslog.h>
  80. X.sp
  81. Xopenlog(ident, arg1, arg2)
  82. X    char *ident;
  83. X    int arg1;
  84. X    int arg2;
  85. X.sp
  86. Xsyslog(priority, message, parameters ... )
  87. X    char *message;
  88. X.sp
  89. Xcloselog()
  90. X.fi
  91. X.SH DESCRIPTION
  92. X.I Syslog
  93. Xis intended to provide a standard error and general notification interface.
  94. XThis version sends errors to the standard error; versions on other system
  95. Xuse IPC mechanisms to talk to a logging daemon.
  96. X.PP
  97. XEach log message is tagged with a
  98. X.IR priority ,
  99. Xdefined in the header file.
  100. XVarious filtering mechanisms are used on other systems to direct the
  101. Xdifferent levels to different destinations.
  102. X.PP
  103. XThe message looks like a
  104. X.IR printf (3)
  105. Xstring except that
  106. X.B %m
  107. Xis replaced by the current error message (collected from
  108. X.IR errno ).
  109. XA newline will be output if the the format string doesn't end with one.
  110. X.PP
  111. XThe
  112. X.I openlog
  113. Xroutine can be called to initialize the logger.
  114. XThis routine takes three parameters.
  115. XThe first is a text string to be output before each message; it is
  116. Xconventionally the program name.
  117. XThe other two parameters are currently ignored, and should be supplied
  118. Xfor compatibility.
  119. X.PP
  120. XThe
  121. X.I closelog
  122. Xroutine can be used to close the log file.
  123. END_OF_FILE
  124. if test 1246 -ne `wc -c <'syslog.3'`; then
  125.     echo shar: \"'syslog.3'\" unpacked with wrong size!
  126. fi
  127. # end of 'syslog.3'
  128. fi
  129. if test -f 'syslog.c' -a "${1}" != "-c" ; then 
  130.   echo shar: Will not clobber existing file \"'syslog.c'\"
  131. else
  132. echo shar: Extracting \"'syslog.c'\" \(2405 characters\)
  133. sed "s/^X//" >'syslog.c' <<'END_OF_FILE'
  134. X/*
  135. X * syslog.c
  136. X *
  137. X * Dummy version of syslog routines that use stdio to stderr.
  138. X * Designed for debugging during development.
  139. X *
  140. X * Arnold Robbins
  141. X * Emory University Computing Center
  142. X * 7/87
  143. X */
  144. X
  145. Xextern int errno;
  146. Xextern int sys_nerr;
  147. Xextern char *sys_errlist[];
  148. X
  149. X/*
  150. X * Surround each header with an ifdef so that
  151. X * the whole file may be included if desired.
  152. X */
  153. X
  154. X#ifndef NULL    
  155. X#include <stdio.h>
  156. X#endif
  157. X
  158. X#ifndef LOG_EMERG
  159. X#include <syslog.h>
  160. X#endif
  161. X
  162. X#ifndef va_dcl
  163. X#include <varargs.h>
  164. X#endif
  165. X
  166. Xstatic char *str;
  167. X
  168. Xint openlog (s, i, j)
  169. Xchar *s;
  170. Xint i, j;
  171. X{
  172. X    str = s;
  173. X#ifdef lint
  174. X    i = i;
  175. X    j = j;
  176. X#endif
  177. X    return(0);
  178. X}
  179. X
  180. Xcloselog () { }
  181. X
  182. Xsetlogmask (mask)
  183. Xint mask;
  184. X{
  185. X#ifdef lint
  186. X    mask = mask;
  187. X#endif
  188. X}
  189. X
  190. Xsyslog (va_alist)
  191. Xva_dcl
  192. X{
  193. X    va_list ap;
  194. X    char *format, c, form[30];
  195. X    int i, j;
  196. X    double d;
  197. X    char *cp, *x;
  198. X    int err = errno, pri;
  199. X    static char *level[] = {
  200. X        "emergency",
  201. X        "alert",
  202. X        "critical",
  203. X        "error",
  204. X        "warning",
  205. X        "notice",
  206. X        "info",
  207. X        "debug"
  208. X    };
  209. X
  210. X    va_start(ap);
  211. X    pri = va_arg(ap, int);
  212. X
  213. X    x = "unknown";
  214. X    if (pri >= LOG_EMERG && pri <= LOG_DEBUG)
  215. X        x = level[pri];
  216. X
  217. X    fprintf (stderr, "%s: %s: ", str, x);
  218. X
  219. X    format = va_arg(ap, char *);
  220. X    while (c = *format++)
  221. X    {
  222. X        int done;
  223. X
  224. X        if (c != '%')
  225. X        {
  226. X            putc (c, stderr);
  227. X            continue;
  228. X        }
  229. X        j = 0;
  230. X        form[j++] = c;
  231. X        done = 0;
  232. X        while (! done)
  233. X        {
  234. X            c = *format++;
  235. X            switch (c) {
  236. X            default:    /* XXX */
  237. X            case 'o': case 'c': case 'd': case 's': case 'u':
  238. X            case 'e': case 'E': case 'f': case 'g': case 'G':
  239. X            case 'x': case 'X':
  240. X                done++;
  241. X                /* fall thru */
  242. X            case ' ': case '+': case '-': case '.': case '#':
  243. X            case '0': case '1': case '2': case '3': case '4':
  244. X            case '5': case '6': case '7': case '8': case '9':
  245. X            case 'l':
  246. X                form[j++] = c;
  247. X                break;
  248. X            case 'm':
  249. X                errno = err;
  250. X                if (errno < sys_nerr)
  251. X                    fputs (sys_errlist[errno], stderr);
  252. X                else
  253. X                    fprintf (stderr, "error %d", errno);
  254. X                goto out;
  255. X            case '%':
  256. X                putc ('%', stderr);
  257. X                goto out;
  258. X            }
  259. X        }
  260. X        form[j] = '\0';
  261. X        switch (form[j-1]) {
  262. X        case 'x':
  263. X        case 'X':
  264. X        case 'o':
  265. X        case 'c':
  266. X        case 'd':
  267. X        case 'u':
  268. X            i = va_arg(ap, int);
  269. X            fprintf (stderr, form, i);
  270. X            break;
  271. X        case 'e':
  272. X        case 'E':
  273. X        case 'f':
  274. X        case 'g':
  275. X        case 'G':
  276. X            d = va_arg(ap, double);
  277. X            fprintf (stderr, form, d);
  278. X            break;
  279. X        case 's':
  280. X            cp = va_arg(ap, char *);
  281. X            fprintf (stderr, form, cp);
  282. X            break;
  283. X        }
  284. X    out: ;
  285. X    }
  286. X    if (format[-1] != '\n')
  287. X        putc ('\n', stderr);
  288. X
  289. X    va_end(ap);
  290. X}
  291. END_OF_FILE
  292. if test 2405 -ne `wc -c <'syslog.c'`; then
  293.     echo shar: \"'syslog.c'\" unpacked with wrong size!
  294. fi
  295. # end of 'syslog.c'
  296. fi
  297. if test -f 'syslog.h' -a "${1}" != "-c" ; then 
  298.   echo shar: Will not clobber existing file \"'syslog.h'\"
  299. else
  300. echo shar: Extracting \"'syslog.h'\" \(673 characters\)
  301. sed "s/^X//" >'syslog.h' <<'END_OF_FILE'
  302. X/*
  303. X**  SYSLOG HEADER FILE
  304. X*/
  305. X
  306. X/*
  307. X**  These are #define's for the various levels, and representative
  308. X**  messages that might indicate their class.
  309. X*/
  310. X#define LOG_ALERT    1    /* The disk is on fire            */
  311. X#define LOG_SALERT    2    /* /bin/rmail is filling up /usr/spool    */
  312. X#define LOG_EMERG    3    /* ??Like SALERT, but send to a file??    */
  313. X#define LOG_ERR        4    /* Network was unreachable, is back    */
  314. X#define LOG_CRIT    5    /* Can't read /usr/lib/news/history    */
  315. X#define LOG_WARNING    6    /* Rnews just dropped an article    */
  316. X#define LOG_NOTICE    7    /* /usr/spool/news is filling up    */
  317. X#define LOG_INFO    8    /* Have 100 new articles in talk.foo    */
  318. X#define LOG_DEBUG    9    /* Expired article <34@site.uucp>    */
  319. END_OF_FILE
  320. if test 669 -ne `wc -c <'syslog.h'`; then
  321.     echo shar: \"'syslog.h'\" unpacked with wrong size!
  322. fi
  323. # end of 'syslog.h'
  324. fi
  325. echo shar: End of shell archive.
  326. exit 0
  327. -- 
  328.  
  329. Rich $alz
  330. Cronus Project, BBN Labs            rsalz@bbn.com
  331. Moderator, comp.sources.unix            sources@uunet.uu.net
  332.